class Point:
    def __init__(self, x=0, y=0):
        self.__x = x
        self.__y = y

    # 静态方法，从一个字符串中解析Point
    # 返回值：(point, err)
    # err 为 True，则说明解析失败，此时point无意义
    @staticmethod
    def parse(raw_point):
        point = Point()
        if len(raw_point) != 2:
            return point, True
        x = raw_point[0]
        if x < 'A' or x > 'H':
            return point, True
        y = raw_point[1]
        if y < '1' or y > '8':
            return point, True
        point.set_x(ord(x) - 64)
        point.set_y(ord(y) - 48)
        return point, False

    # 判断是否相等
    def equals(self, point) -> bool:
        return (self.get_x() == point.get_x()
                and self.get_y() == point.get_y())

    # 判断是否越界
    def is_off_border(self) -> bool:
        return (self.get_x() < 1 or self.get_x() > 8
                or self.get_y() < 1 or self.get_y() > 8)

    # 设置row属性
    def set_x(self, x) -> None:
        self.__x = x

    # 返回row属性
    def get_x(self) -> int:
        return self.__x

    # 设置col属性
    def set_y(self, y) -> None:
        self.__y = y

    # 返回col属性
    def get_y(self) -> int:
        return self.__y


if __name__ == '__main__':
    a, b = Point.parse('A4')
    print(a.get_x(), a.get_y(), b)
    a, b = Point.parse('A4H')
    print(a.get_x(), a.get_y(), b)
    a, b = Point.parse('A9')
    print(a.get_x(), a.get_y(), b)
    a, b = Point.parse('Z8')
    print(a.get_x(), a.get_y(), b)
    a, b = Point.parse('Z9')
    print(a.get_x(), a.get_y(), b)

    a, b = Point.parse('F7')
    print(a.equals(a))
    c, b = Point.parse('F8')
    print(a.equals(c))
